<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <!-- <el-form-item label="标题" prop="title">
        <el-input
          v-model="queryParams.title"
          placeholder="请输入资讯标题"
          clearable
          size="small"
        />
      </el-form-item> -->
       <el-form-item label="官网搜索">
            <el-select v-model="queryParams.code" placeholder="请选择">
            <el-option label="时代科技" value="1">时代科技</el-option>
            <el-option label="商学院" value="2">商学院</el-option>
            </el-select>
    </el-form-item>
      <!-- <el-form-item label="创建时间" prop="noticeType">
        <el-date-picker
          v-model="queryParams.createTime"
          type="date"
          placeholder="选择日期时间"
          value-format="yyyy-MM-dd"
        >
        </el-date-picker>
      </el-form-item> -->
      <el-form-item>
        <el-button
          type="cyan"
          icon="el-icon-search"
          size="small"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="small" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-card shadow="hover">
      <div style="padding: 10px 0;">
      </div>
      <el-table
        v-loading="loading"
        :data="noticeList"
        border
      >
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column 
          label="分配网站"
          align="center"
          prop="code"
          :formatter="(row,column) => row.code == 1?'时代科技':row.code == 2?'商学院':'-'"
        >
        </el-table-column>
        <el-table-column 
          label="网页标题"
          align="center"
          prop="name"
          :show-overflow-tooltip="true"
        >
        </el-table-column>
        <el-table-column
          label="标题"
          align="center"
          prop="title"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          label="描述"
          align="center"
          prop="description"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          label="关键词"
          align="center"
          prop="keywords"
          :show-overflow-tooltip="true"
        />
        <!-- <el-table-column label="创建时间" align="center" prop="createTime">
          <template slot-scope="scope">
            {{formatT(scope.row.createTime)}}
          </template>
        </el-table-column> -->
        <el-table-column
          label="操作"
          align="center"
          class-name="small-padding fixed-width"
        >
          <template slot-scope="scope">
            <el-button
              size="small"
              type="text"
              icon="el-icon-edit"
              @click="handleUpdate(scope.row)"
              >修改</el-button
            >
            <!-- <el-button
              size="small"
              type="text"
              icon="el-icon-delete"
              @click="handleDelete(scope.row)"
              >删除</el-button
            > -->
          </template>
        </el-table-column>
      </el-table>
    </el-card>

    <!-- <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    /> -->

    <!-- 添加或修改对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="780px" append-to-body>
      <el-form ref="form" :model="form" label-width="80px">
        <el-row>
          <el-col :span="24">
            <el-form-item label="网页标题">
              <el-input v-model="form.name" placeholder="请输入标题" />
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="标题">
              <el-input v-model="form.title" placeholder="请输入标题" />
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="描述" >
              <el-input
                type="textarea" 
                :autosize="{ mainRows: 2 }"
                v-model="form.description" 
                placeholder="请输入一句话简述" 
              />
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="关键词" >
              <el-input
                type="textarea"
                :autosize="{ minRows: 3 }"
                v-model="form.keywords"
                placeholder="请输入内容"
              />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer" style="padding-top: 30px">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  delClassList,
  updateClassList,
  addClassList,
  coodList,
  delList
} from "@/api/system/classList";
import Editor from "@/components/Editor";
import { getToken } from "@/utils/auth";
export default {
  name: "Notice",
  components: {
    Editor,
  },
  data() {
    return {
      headers: { Authorization: "Bearer " + getToken() },
      baseUrl: process.env.VUE_APP_BASE_API,
      certificate_pic: "",
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 公告表格数据
      noticeList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 类型数据字典
      statusOptions: [],
      // 状态数据字典
      typeOptions: [],
      // 查询参数
      queryParams: { 
        pageNum: 1,
        pageSize: 10,
        code: undefined,
      },
      // 表单参数
      form: {},
     
    };
  },
  created() {
    this.getList();
  },
  methods: {
    uploadPicUrl(res) {
      // console.log(res);
      this.form.cover = res.data;
    },
    handleAvatarSuccess(res, file) {
      this.certificate_pic = URL.createObjectURL(file.raw);
    },
    /** 查询列表 */
    getList() {
      this.loading = true;
      coodList(this.queryParams).then((response) => {
          console.log(response,'1111111111111')
        this.noticeList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
     handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
    this.queryParams ={
        pageNum: 1,
        pageSize: 10,
        code: undefined,
    }
      this.getList()
    },
    // 反编译
    typeFormat(row, column) {
      return this.selectDictLabel(this.typeOptions, row.noticeType);
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        cover: undefined,
        title: undefined,
        theme: undefined,
        context: undefined,
        code:undefined
      };
      this.resetForm("form");
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();  
      
      this.open = true;
      this.title = "添加";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      console.log(row)
      this.reset();
      this.form = row;
      this.open = true;
      this.title = "修改";
    },
    /** 提交按钮 */
    submitForm: function () {
      this.$refs["form"].validate((valid) => {
        if (valid) {
            delList(this.form).then((response) => {
              if (response.code === 200) {
                this.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              }
            });
          } 
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const noticeIds = row.id || this.ids;
      this.$confirm("是否确认删除?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(function () {
          return delClassList(noticeIds);
        })
        .then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
        .catch(function () {});
    },
  },
};
</script>
<style scoped>
.img {
  display: block;
  width: 60px;
  height: 60px;
  margin: auto;
  border-radius: 5px;
}
.avatar-uploader .el-upload {
  width: 148px;
  height: 148px;
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

.avatar-uploader .el-upload:hover {
  border-color: #20a0ff;
}

.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 148px;
  height: 148px;
  line-height: 148px;
  text-align: center;
  border: 1px dashed #ccc;
}

.avatar {
  width: 148px;
  height: 148px;
  display: block;
}
</style>